import { getCurPage } from './util'
import {handleMenu} from '@/utils/wxPrompt'
//登录失效
export function goLogin() {

  if (getCurPage().$route.fullPath) {
    uni.setStorageSync('url-path', getCurPage().$route.fullPath)
  }
  uni.showModal({
    title: '温馨提示',
    content: '您的登录已失效，请登录后再操作',
    cancelText: '取消',
    confirmText: '去登录',
    success: (res) => {
      if (res.confirm) {
        handleMenu('/pages/login/login')
        //token之的缓存清除 掉
      }
    },
  })
}
//用星号代码
export function asterisk(str, subLen = 3, repeat = 4, len = 4) {
  return str.substr(0, subLen) + '*'.repeat(repeat) + str.substr(len, str.length - 1)
}
function getStr(str, start, end) {
  const res = str.match(new RegExp(`${start}(.*?)${end}`))
  return res ? res[1] : null
}
//跳第三方页面
export function indexOfencodeURIComponent(url,sceneName) {
  if (url == '') {
    console.log('没有配置场景地址')
    return
  }
  console.log(url)
  if (url.indexOf('null') != -1) {
    url = getStr(url, '&redirectUrl=', '&timestamp')
  }
  console.log(url.indexOf('http'))
  if (url.indexOf('http') != -1) {
    url = '/pages/webview/webview?url=' + encodeURIComponent(url)+'&title='+encodeURIComponent(sceneName)+'&type=1'
  }
  console.log('url--',url)
  console.log('sceneName-111-',sceneName)
  //return;
  //handleLink('/pages/webview/webview?url=http://app15.hzgsredcross.org.cn/Home/Szqt/?mobile=13111111111&nickname=13111111111&pid=330106198502263019&redirectUrl=http://app15.hzgsredcross.org.cn/JKDetailInfo/indexNew&timestamp=1618579963262&userToken=1379693441818066946&sign=ec77509ea99f0a013366afb691c99405');
  if (!url) return false

  uni.navigateTo({
    url: url
  })
}
export function encodeURIComponentUrl(url,title){
  url = '/pages/webview/webview?url=' + encodeURIComponent(url)
  uni.navigateTo({
    url: url,
	title:title
  })
}
